#! /usr/bin/env python
# -*- coding: utf-8 -*-

# *************************************************************
#     Filename @  defaultdict.py
#       Author @  Huoty
#  Create date @  2016-07-02 20:38:07
#  Description @  default dict
# *************************************************************


class defaultdict(dict):
  def __init__(self, default_factory=None, *a, **kw):
      dict.__init__(self, *a, **kw)
      self.default_factory = default_factory

  def __missing__(self, key):
      self[key] = value = self.default_factory()
      return value

# Script starts from here

if __name__ == "__main__":
    dct = defaultdict(lambda: float("nan"))
    print dct
    print dct["one"]
